<template>
  <div class="cc_home">
    <search @result-click="resultClick" @on-change="getResult" :results="results" v-model="value" placeholder="搜索"
            cancelText="取消"></search>
    <swiper loop auto :list="baseList"></swiper>
    <panel :list="list" type="1"></panel>
  </div>
</template>

<script type="text/ecmascript-6">
  import {
          Search,
          Panel,
          Group,
          Swiper,
          SwiperItem
  } from 'vux';

  import {bus} from '../../bus.js';

  export default {
    components: {
      Search,
      Panel,
      Group,
      Swiper,
      SwiperItem
    },
    methods: {
      resultClick(item) {
        window.alert('you click the result item: ' + JSON.stringify(item))
      },
      getResult(val) {
        this.results = val ? getResult(this.value) : []
      }
    },
    data() {
      return {
        value: '',
        results: [],
        list: [
          {
          src: 'http://placeholder.qiniudn.com/60x60/3cc51f/ffffff',
          title: '标题一',
          desc: '由各种物质组成的巨型球状天体，叫做星球。星球有一定的形状，有自己的运行轨道。',
          url: 'list/v/cell'
        }, {
          src: 'http://placeholder.qiniudn.com/60x60/3cc51f/ffffff',
          title: '标题二',
          desc: '由各种物质组成的巨型球状天体，叫做星球。星球有一定的形状，有自己的运行轨道。',
          url: {
            path: 'list/v/radio',
            replace: false
          }
        }],
        baseList: [{
          url: '/sell',
          img: 'https://static.vux.li/demo/1.jpg',
          title: '送你一朵fua'
        }, {
          url: 'javascript:',
          img: 'https://static.vux.li/demo/2.jpg',
          title: '送你一辆车'
        }, {
          url: 'javascript:',
          img: 'https://static.vux.li/demo/3.jpg',
          title: '送你一次旅行'
        }]
      }
    },
    created() {
      this.$http.get('/io/index').then(response => {
        if (response.body.success === "true") {
          this.commList = Object.assign({}, this.commList, response.body.paramdata[0])
          console.log(this.commList);
        }
      });
      bus.$emit('coco');
    }
  }

  function getResult(val) {
    let rs = []
    for (let i = 0; i < 8; i++) {
      rs.push({
        title: `${val} result: ${i + 1} `,
        other: i
      })
    }
    return rs
  }
</script>

<style lang="less">
  .cc_home{
    position: absolute;
    width: 100%;
    top: 0;
    left: 0;
    bottom: 50px;
  }
</style>
